<?php
require_once('../../includes/global.php');
?>
<SCRIPT LANGUAGE="JavaScript">
<!--
function lm_Dsy(){
this.Items = {};
}
lm_Dsy.prototype.add = function(id,iArray){
this.Items[id] = iArray;
}
lm_Dsy.prototype.Exists = function(id){
if(typeof(this.Items[id]) == "undefined") return false;
return true;
} 

function lm_change(v){
var str="0";
for(i=0;i<v;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
  length = 0;
  options[0]=new Option(opt0[v],opt0[v]);
  if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
  {
   if(lm_Dsy.Exists(str)){
    ar = lm_Dsy.Items[str];
    for(i=0;i<ar.length;i++)options[length]=new Option(ar[i],ar[i]);
    if(v)options[1].selected = true;
   }
  }
  if(++v<s.length){lm_change(v);}
}
}

var lm_Dsy = new lm_Dsy();
<?php
/**/
$ceshu=3;
function gsi($id){
	$temp=getsomeinfo('sort'," parentid= '".$id."'");
	foreach($temp as $value){
		$var[title][]=$value[zh];
		$var[id][]=$value[id];
	}
	return $var;
}
function gjs($key,$var){
		$str=implode("\",\"",$var);
	//	echo $str;
		$str="lm_Dsy.add(\"".$key."\",[\"".$str."\"]);\n";
		return $str;
}
function gks($key,$fu){
if($fu!=''){
	return $fu."_".$key;
}else{
	return $key;
}
}
$ceshu=3;
$did=1;
//第一层

$temp=gsi($did);
$jsstr.=gjs(0,$temp[title]);
//第二层
foreach ($temp[id] as $key=> $value){
$tempa[$key]=gsi($value);
$jsstr.=gjs("0_".$key,$tempa[$key][title]);
}
/*//第三层
foreach ($temp[id] as $key=> $value){
		foreach($tempa[$key][id] as $key1 => $value1){
		$tempb[$key][$key1]=gsi($value1);
		$jsstr.=gjs("0_".$key."_".$key1,$tempb[$key][$key1][title]);
		} 
}*/
//第四层

echo $jsstr;
?>
var s=["s1","s2"];
var opt0 = ["省","市"];
function lm_setup()
{
for(i=0;i<s.length-1;i++)
  document.getElementById(s[i]).onchange=new Function("lm_change("+(i+1)+")");
lm_change(0);
}
//-->
</SCRIPT>
</head>
<body onLoad="lm_setup()">

<form name="frm" action="test.php" method="post">
<select id="s1" name ="province"><option>省</option></select>
<select id="s2" name='city'><option>省份</option></select>
<input type="submit">
</form>
</body>
</html>
/**/?>